/**
 * @module
 */
import * as redis from './redis';
import * as serverConfig from '../config/config';

export let _redisIns:redis.Redis[] =[];


/**
 *  获取一个redis实例,根据配置文件信息，创建实例
 * @returns redis
 */
export function getRedis(){
    let dbName = parseInt(serverConfig.getServerConfig().redis.dbName);
    if(_redisIns[dbName]){
        return _redisIns[dbName] ;
    }
    let option :redis.OptionClient = {} as redis.OptionClient;
    option.port = serverConfig.getServerConfig().redis.port;
    option.host = serverConfig.getServerConfig().redis.host;
    if(serverConfig.getServerConfig().redis.pwd)
        option.password = serverConfig.getServerConfig().redis.pwd;
    option.dbName =dbName;
    option.prefix = serverConfig.getServerConfig().redis.prefix;
    _redisIns[option.dbName] = new redis.Redis(option);
    return _redisIns[option.dbName];
}